package com.miyake.dsp.ui;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JPanel;

public class DspCompositeUiChooser extends JDialog {
	private List<String> list;
	private String selectedItem;
	
	public DspCompositeUiChooser() {
		this.setSize(300, 200);
	}
	
	public void setItems(List<String> list) {
		this.list = list;
		
		this.getContentPane().setLayout(new FlowLayout());
		this.getContentPane().add(createAddItem());
		this.getContentPane().add(createOkCancel());
	}
	
	private JPanel createAddItem() {
		final JComboBox combo = new JComboBox();
		JPanel panel = new JPanel();

		for (String s : list) {
			combo.addItem(s);
		}
		
		panel.add(combo);
		combo.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				selectedItem = (String)combo.getSelectedItem();
			}
			
		});
		panel.setBounds(0, 0, 300, 40);
		return panel;
	}
	
	private JPanel createOkCancel() {
		JPanel panel = new JPanel();
		panel.setLayout(new FlowLayout());
		JButton ok = new JButton("OK");
		JButton cancel = new JButton("Cancel");
		panel.add(ok);
		panel.add(cancel);
		
		ok.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
			}
		});
		return panel;
	}

	public String getSelectedItem() {
		return selectedItem;
	}

	public void setSelectedItem(String selectedItem) {
		this.selectedItem = selectedItem;
	}
	
}
